<template>
  <div id="register">
    <div class="toptitle">
      <div class="left">
        <img src="../../../static/images/retrieve-logo.png" />
        <span>|</span>
        <h3>{{isQuery?'查询申请状态':'申请合伙人'}}</h3>
      </div>
      <div class="right">
        <h3 @click='backlogin()' style='cursor: pointer;color:#2970CC;font-size:20px'>返回登录</h3>
      </div>
    </div>
    <!-- 在原来样式基础上做的修改 shilin -->
    <div class="retrievewrap">
       <el-button class="check-btn" @click="changeFun">{{isQuery?'去申请合伙人':'查询申请状态'}}</el-button>
      <div class="retrieveitem phoneitem" :class="[check==1?'onshow':'']" v-if="!isQuery">
        <span>姓   名</span>
        <el-input type="text" v-model="name" placeholder="请输入姓名" @focus="focus(1)"  maxlengt="16"></el-input>
        <span class="str">*</span>
      </div>
      <div class="retrieveitem phoneitem" :class="[check==2?'onshow':'']">
        <span>手机号码</span>
        <el-input  type="number"  v-model="phone" placeholder="请输入手机号码" @focus="focus(2)" maxlength="11"></el-input>
        <span class="str">*</span>
      </div>
      <div class="retrieveitem phoneitem" :class="[check==3?'onshow':'']" v-if="!isQuery">
        <div class="leftinput inputcode">
          <span>短信验证码</span>
          <el-input type="number" v-model="code"  placeholder="填写6位短信验证码" @focus="focus(3)" maxlength='8'></el-input>
        </div>
        <div class="codebtn">
          <span v-show="show" @click="getCode">获取验证码</span>
          <span v-show="!show" class="count">{{count}} s重发</span>
        </div>
        <span class="str">*</span>
      </div>
      <div class="retrieveitem phoneitem" :class="[check==4?'onshow':'']" v-if="!isQuery">
        <span class="site_bar">优势说明</span>
         <!-- <textarea name="textarea" v-model="remarks" cols="40" rows="5" placeholder="请输入优势说明" maxlength="200"  @focus="focus(4)"></textarea> -->
          <el-input type="textarea" v-model="remarks"  @focus="focus(4)" placeholder="请输入优势说明" cols="40" rows="5" maxlength="200"  ></el-input>
      </div>
      <div class="confirmBox">
        <button class="confirm" v-if="isQuery" @click="queryFun">查询</button>
        <button class="confirm" v-else @click="confirm">申请</button>
      </div> 
    </div>
    
    <!-- 小黑窗 -->
    <div class="modelwrap">
      <p>{{modelmsg}}</p>
    </div>
  </div>
</template>
<script>
export default {
  name: 'register',
  data() {
    return {
      check:0,
      show: true,
      count: '',
      timer: null,
      modelmsg: '',
      name:'',
      phone: '', //手机号码
      code:'',
      remarks:'',//备注
      isQuery:false,
    }
  },
  methods: {
    focus(e){
      this.check=e;
    },
    // 路由
    backlogin() {
      this.$router.go(-1);
    },
    //切换效果
    changeFun(){
      this.isQuery=!this.isQuery;
    },
        // 获取验证码
    getCode() {
      var that = this;
      var phone = that.phone;
      var pattern =   /^(1[3-9])\d{9}$/; 
      if(that.stop){
        return false
      }
      that.stop=true;
      setTimeout(()=>{
        that.stop=false
      },2000)
      if (phone == '') {
        that.modelmsg = "手机号码不能为空";
        $('.modelwrap').fadeIn().delay(1500).fadeOut();
         return false;
      } else if (!pattern.test(phone)) {
        that.modelmsg = "手机号码错误";
        $('.modelwrap').fadeIn().delay(1500).fadeOut();
         return false;
      }
      that.$post({
        url: 'Common/Common/sendSms',
        data: { phone: phone },
        success: (data) => {
          if (data.code == 1000) {
            that.modelmsg = data.message;
            $('.modelwrap').fadeIn().delay(1500).fadeOut();
            // 跳转登录页面
 				that.cundrion();//倒计时方法
          } else {
            that.modelmsg = data.message;
            $('.modelwrap').fadeIn().delay(1500).fadeOut();
          }
        }
      })
    },
    //倒计时
    cundrion(){
    	var that=this;
        var TIME_COUNT = 120;
    if (!this.timer) {
      this.count = TIME_COUNT;
      this.show = false;
      this.timer = setInterval(() => {
        if (this.count > 0 && this.count <= TIME_COUNT) {
          this.count--;
        } else {
          this.show = true;
          clearInterval(this.timer);
          this.timer = null;
        }
      }, 1000)
    }
    },

    //确认
    confirm() {
      var that = this;
       var pattern =   /^(1[3-9])\d{9}$/; 
        if(that.stop){
        return false
      }
      that.stop=true;
      setTimeout(()=>{
        that.stop=false
      },2000);
      var name= that.name;
      var phone= that.phone;
      var code= that.code;
      var remarks= that.remarks;
      // 判断数据是否为空
      if (name == "") {
        this.modelmsg = "姓名不能为空";
        $('.modelwrap').fadeIn().delay(1500).fadeOut();
        return false;
      } else if (phone == "") {
        this.modelmsg = "手机号码不能为空";
        $('.modelwrap').fadeIn().delay(1500).fadeOut();
        return false;
      }else if (!pattern.test(phone)) {
        that.modelmsg = "手机号码错误";
        $('.modelwrap').fadeIn().delay(1500).fadeOut();
         return false;
      } else if (code == '') {
        this.modelmsg = "验证码不能为空";
        $('.modelwrap').fadeIn().delay(1500).fadeOut();
        return false;
      } 

      // ajax请求
      that.$post({
        url: 'Partner/User/applyPartner',
        data: { name,phone,remarks,code },
        success: (data) => {
          if (data.code == 1000) {
            this.modelmsg = data.message;
            $('.modelwrap').fadeIn().delay(2000).fadeOut();
            // 跳转登录页面
            setTimeout(() => {
              this.$router.go(-1);
            }, 2000);
            this.$message({
              type: 'success',
              showClose: true,
              message: data.message,
              center: true
            });
          } else {
            this.modelmsg = data.message;
            $('.modelwrap').fadeIn().delay(1500).fadeOut();
          }
        }
      })
    },
    //查询手机号码
    queryFun(){
      var that = this;
      var pattern =   /^(1[3-9])\d{9}$/; 
        if(that.stop){
        return false
      }
      that.stop=true;
      setTimeout(()=>{
        that.stop=false
      },2000);
      var phone= that.phone;
      // 判断数据是否为空
       if (phone == "") {
        this.modelmsg = "手机号码不能为空";
        $('.modelwrap').fadeIn().delay(1500).fadeOut();
        return false;
      }else if (!pattern.test(phone)) {
        that.modelmsg = "手机号码错误";
        $('.modelwrap').fadeIn().delay(1500).fadeOut();
         return false;
      } 
      // ajax请求
      that.$post({
        url: 'Partner/User/applyDetail',
        data: { tel:phone},
        success: (data) => {
          if (data.code == 1000) {
            var apply_status=data.data.apply_status;//apply_status 1申请中  2申请通过  3申请拒绝',
            this.showPop(apply_status);
          }else if(data.code == -2000){
              this.$confirm('暂时还未提交申请，是否去申请?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
                center: true,
              }).then(() => {
                this.isQuery=false;
              }).catch(() => {       
              });
          }else{
              that.modelmsg = data.message;
              $('.modelwrap').fadeIn().delay(1500).fadeOut();
          }
        }
      })
    },
    //修改展示弹窗 //apply_status 1申请中  2申请通过  3申请拒绝',
    showPop(apply_status){
       var that=this;
        var html="";
			 	html+="<div class='PopBackMsg'>"
			 	html+="<h2>申请状态</h2>"
			 	html+="<div class='PopBackTitle'></div>"
				html+="<div class='PopBackTitle'></div>"
				html+="<div class='list-title'></div>"
				html+="<div class='errorLis'>"
        html+="<div class='success-box'>"
        html+=apply_status==1?"<img src='/static/images/hint-icons.png'>":''
        html+=apply_status==2?"<img src='/static/images/successicon2.png'>":''
        html+=apply_status==3?"<img src='/static/images/failicon.png'>":''
        html+=apply_status==1?"<div class='success-hint'>申请中,请耐心等待。</div>":''
        html+=apply_status==2?"<div class='success-hint'>恭喜您,申请通过!</div>":''
        html+=apply_status==3?"<div class='success-hint'>审核未通过。</div>":''
        html+="</div>"
				html+="</div>"
				this.$confirm(html, {
					center: true,
					dangerouslyUseHTMLString: true,
					confirmButtonText: '确认',
					cancelButtonText: '取消',
				}).then(()=>{

				}).catch(() => {

				});
    }

  },
  mounted() {

  },
  created() {}
}

</script>
<style>
#register {
  width: 1200px;
  margin: 0 auto;
}

#register .toptitle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #d9d9d9;
  font-size: 24px;
  font-weight: bold;
  margin-top: 80px;
  padding-bottom: 10px;
}

#register .toptitle .left {
  display: flex;
  align-items: center;
}

#register .toptitle span {
  color: #d9d9d9;
  font-weight: normal;
  padding: 0 15px;
}

#register .retrievewrap {
  margin-top: 80px;
  position:relative;
  min-height: 60vh;
}

#register .retrieveitem {
  width: 400px;
  margin: 0 auto;
  padding: 8px 10px;
  border-bottom: 1px solid #d9d9d9;
  display: flex;
  margin-bottom: 37px;
  align-items: flex-start;
  line-height: 36px;
  position: relative;
}

#register .retrieveitem span {
  font-size: 16px;
  font-weight: bold;
  width: 30%;
}

#register .retrieveitem .leftinput span {
  text-align-last:justify;
  padding-right: 30px;
}

#register .retrieveitem input {
  border: none;
  font-size: 16px;
}
#register .inputcode  .el-input {
  width:60%;
}

#register .retrieveitem textarea {
  border: none;
  font-size: 16px;
  resize:none;
  padding: 2px;
  box-sizing: border-box;
  border:1px solid #999;
}

#register .phoneitem {
  background-image : linear-gradient(#2970cc,#2970cc);
  background-position:center bottom;
  background-size:0 2px;
  background-repeat:no-repeat;
  transition:.3s;
}
#register .phoneitem:hover{
  background-size : 100% 2px;
}
#register .onshow{
  background-size : 100% 2px;
}
#register .retrieveitem .codebtn{
  width: 100px;
}
#register .retrieveitem .codebtn span {
  cursor: pointer;
  font-size: 16px;
  line-height: 20px;
  color: #FF6565;
  font-weight: normal;
}

#register .retrieveitem .codebtn .count {
  color: #d9d9d9;
  cursor: auto;
}

#register .justy {
  justify-content: space-between;
}

#register .retrieveitem img {
  width: 22px;
  height: 15px;
}
#register .retrievewrap .check-btn {
  position: absolute;
  top:1%;
  right:10%;
}
#register .retrievewrap .confirmBox {
  width:100%;
  position: absolute;
  left:0;
  margin: 0 auto;
  bottom:15px;
  display:flex;
  justify-content: center;
  align-items: center;
}
#register .retrievewrap .confirm {
  background-color: #2970cc;
  border-radius: 5px;
  border: none;
  color: #FFF;
  font-size: 18px;
  width: 420px;
  margin: 0 auto;
  display: block;
  height: 50px;
  cursor: pointer;
}


#register .modelwrap {
  width: 350px;
  height: 120px;
  border-radius: 5px;
  text-align: center;
  line-height: 120px;
  background-color: rgba(0, 0, 0, 0.7);
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  margin: auto;
  color: #FFF;
  font-size: 18px;
  display: none;
}

#register .modelwrap p {
  margin: 0;
}
#register  .str{
  position: absolute;
  top:12px;
  right:10px;
  color:#FF6000;
  width:5px!important;
}

</style>
